<%@ include file="/common/taglibs.jsp"%>
<%--
Note: to use this file, include this JSP inside a form.
Then in the controller, use getPagingBean() to pass to the BO and then DAO.
--%>
<script type="text/javascript" defer>
var fnOnGoToPage${pagingId};
function gotoPage${pagingId}(pageNo) {
	if(isNaN(pageNo) || pageNo <= 0){
		alert("页码，请填写数字！");
		return false;
	}
	$("PrmPageNo").value=pageNo;
	//当页面存在fnOnGoToPage时，不自动提交表单，调用fnOnGoToPage
	if(fnOnGoToPage${pagingId}){
		fnOnGoToPage${pagingId}(pageNo);
	}else{
		document.getElementById("PrmPageNo").form.submit();
	}
	return false;
}
</script>


<c:if test="${sc.totalPageCount>0}">
	<div class=pagination>

		<c:if test="${sc.totalPageCount>1}">
			<c:choose>
				<c:when test="${sc.pageNo<=1}">
					<a  class="no_first" title='<fmt:message key="list.paging.goto1"/>' ></a>
				</c:when>
				<c:otherwise>
					<a  href="javascript:void(0)" class="first" title='<fmt:message key="list.paging.goto1"/>' onclick='gotoPage${pagingId}(1);return false;'></a>
				</c:otherwise>
			</c:choose>
			
			<c:choose>
				<c:when test="${sc.pageNo<=1}">
					<a  class="no_prev1" title='<fmt:message key="list.paging.prev"/>'></a>
				</c:when>
				<c:otherwise>
					<a href="javascript:void(0)" class="prev1" title='<fmt:message key="list.paging.prev"/>'	onclick='gotoPage${pagingId}(<c:choose><c:when test="${(sc.pageNo-1) lt 1}">1</c:when><c:otherwise>${sc.pageNo-1}</c:otherwise></c:choose>);return false;'></a>
				</c:otherwise>
			</c:choose>

			<c:set var="minPager"
				value="${(sc.totalPageCount-sc.pageNo>=4)?(sc.pageNo >= 5 ? sc.pageNo - 4
                      : 1):(sc.pageNo >= (5 + 4 - sc.totalPageCount + sc.pageNo) ? (sc.pageNo
                              - 8 + sc.totalPageCount - sc.pageNo) : 1)}" />
			<c:set var="maxPager"
				value="${(minPager + 8 > sc.totalPageCount) ? sc.totalPageCount : (minPager + 8)}" />
			<c:forEach var="idx" begin="${minPager}" end="${maxPager}" step="1">
				<c:if test="${sc.pageNo!=idx}">
					<a href="javascript:gotoPage${pagingId}(${idx});void(0)"
						title="<fmt:message key="list.paging.gotoN"><fmt:param>${idx}</fmt:param></fmt:message>">${idx}
					</a>
				</c:if>
				<c:if test="${sc.pageNo==idx}">
					<a class="curr"> ${idx} </a>
				</c:if>
			</c:forEach>

			<c:choose>
				<c:when test="${sc.pageNo>=sc.totalPageCount}">
					<a  class="no_next2" title='<fmt:message key="list.paging.next"/>' ></a>
				</c:when>
				<c:otherwise>
					<a href="javascript:void(0)" class="next2" title='<fmt:message key="list.paging.next"/>' 	onclick='gotoPage${pagingId}(<c:choose><c:when test="${(sc.pageNo+1) gt sc.totalPageCount}">${sc.totalPageCount}</c:when><c:otherwise>${sc.pageNo+1}</c:otherwise></c:choose>);return false;'	></a>
				</c:otherwise>
			</c:choose>

			<c:choose>
				<c:when test="${sc.pageNo>=sc.totalPageCount}">
					<a class="no_last" title='<fmt:message key="list.paging.gotoEnd"/>'></a>
				</c:when>
				<c:otherwise>
					<a href="javascript:void(0)" class="last" title='<fmt:message key="list.paging.gotoEnd"/>' onclick='gotoPage${pagingId}(${sc.totalPageCount});return false;'></a>
				</c:otherwise>
			</c:choose>
			
			<input type="text" style="width:40px" class="inputtxt" value="${sc.pageNo}" id="pager_input" onkeyup="value=value.replace(/[^\d]/g,'');" />
			<a href="javascript:void(0)"  class="goto" onclick="gotoPage${pagingId}(document.getElementById('pager_input').value);return false;" ></a>

		</c:if>

	</div>
	<input type="hidden" id="PrmPageNo" name="PrmPageNo" value="${sc.pageNo}">
</c:if>